﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SIMCObjetoNegocio;

namespace SIMCRepositorio
{
    public class RepositorioValor : Database, IRepositorioValor
    {
        public List<ValorDeAtributo> BuscarLista(string p_Atributo)
        {
            try
            {
                var query = from valor in Context.cla_valores
                            where valor.cav_satributo == p_Atributo
                            select new ValorDeAtributo
                            {
                                Valor = valor.cav_scodigo,
                                Descripcion = valor.cav_sdescripcion,
                                //Calificadores = new List<string>
                                //{
                                //    valor.cav_scal1,
                                //    valor.cav_scal2,
                                //    valor.cav_scal3
                                //}
                                cav_scal1 = valor.cav_scal1,
                                cav_scal2 = valor.cav_scal2,
                                cav_scal3 = valor.cav_scal3
                            };

                return query.ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public ValorDeAtributo Buscar(string p_Atributo, string p_Valor)
        {
            try
            {
                var query = from valor in Context.cla_valores
                            where valor.cav_satributo == p_Atributo
                            && valor.cav_scodigo == p_Valor
                            select new ValorDeAtributo
                            {
                                Valor = valor.cav_scodigo,
                                Descripcion = valor.cav_sdescripcion,
                                //Calificadores = new List<string>
                                //{
                                //    valor.cav_scal1,
                                //    valor.cav_scal2,
                                //    valor.cav_scal3
                                //}
                                cav_scal1 = valor.cav_scal1,
                                cav_scal2 = valor.cav_scal2,
                                cav_scal3 = valor.cav_scal3
                            };

                return query.FirstOrDefault();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }

    public interface IRepositorioValor
    {
        List<ValorDeAtributo> BuscarLista(string p_Atributo);
        ValorDeAtributo Buscar(string p_Atributo, string p_Valor);
    }
}
